<template>
	<div class="post" @click="$router.push({path: `/articleDetail/?articleId=${post.id}`})">
		<!-- 路由要改变  /:id 动态路由的路径会多几个接收参数的占位符 -->
		<!-- 一张图 -->
		<div class="onePic" v-if="post.type === 1 && post.cover.length < 3">
			<div class="left">
				<h3 class="title">{{ post.title }}</h3>
				<p class="desc">
					<span>{{ post.user.nickname }}</span>
					<span>{{ post.comment_length }}跟帖</span>
				</p>
			</div>
			<div class="right">
				<van-image width="100%" height="100%" fit="cover" :src="post.cover[0].url | imgUrl" />
			</div>
		</div>
		<!-- 多张图 -->
		<div class="morePic" v-if="post.type === 1 && post.cover.length >= 3">
			<h3 class="title">{{ post.title }}</h3>
			<div class="center">
				<van-image v-for="item in post.cover" :key="item.id" fit="cover" :src="item.url | imgUrl" />
			</div>
			<p class="desc">
				<span>{{ post.user.nickname }}</span>
				<span>{{ post.comment_length }}跟帖</span>
			</p>
		</div>
		<!-- 视频 -->
		<div class="video" v-if="post.type === 2">
			<h3 class="title">{{ post.title }}</h3>
			<div class="center">
				<van-image width="100%" height="100%" fit="cover" :src="post.cover[0].url | imgUrl" />
				<i class="iconfont iconshipin"></i>
			</div>
			<div class="desc">
				<p>
					<span>{{ post.user.nickname }}</span>
					<span>{{ post.comment_length }}跟帖</span>
				</p>
			</div>
		</div>
	</div>
</template>

<script>
// import axios from "@/utils/request";

export default {
	props: {
		// post 变量的类型要求是对象，而且必须传递
		post: {
			type: Object,
			required: true,
		},
	}, // 局部过滤器
	// filters: {// imgUrl 是过滤器名称
	// 	imgUrl(val) { // val    过滤器要处理的原始数据
	// 		if (val.indexOf("http") === -1) {
	// 如果没有 http 开始，就需要拼接成完整的图片地址
	// 			return axios.defaults.baseURL + val;
	// 		}
	// 		return val; // 是 http 开头，就直接返回即可
	// 	},
	// },
};
</script>

<style lang="less" scoped>
.desc {
	font-size: 14px;
	color: #ccc;
	span {
		padding-right: 12px;
	}
}
.onePic {
	// background-color: blue;
	height: 80px;
	display: flex;
	padding: 12px;
	.left {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}
	.right {
		height: 75px;
		width: 120px;
	}
	.title {
		width: 200px;
		height: 50px;
		font-size: 18px;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
	}
}
.morePic {
	// background-color: pink;
	padding: 12px;
	height: 120px;
	.title {
		font-size: 18px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.center {
		height: 80px;
		display: flex;
		justify-content: space-between;
		padding: 10px 0;
		.van-image {
			width: 33%;
		}
	}
}
.video {
	padding: 12px;
	// background-color: red;
	.title {
		font-size: 18px;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.center {
		position: relative;
		padding: 10px 0;
		height: 160px;
		.iconfont {
			position: absolute;
			left: 50%;
			top: 50%;
			transform: translate(-50%, -50%);
			font-size: 50px;
			z-index: 1;
			color: #fff;
			border-radius: 25px;
			background-color: rgba(204, 204, 204, 0.685);
		}
	}
}
</style>
